import {createRouter,createWebHistory} from "vue-router";
import StaffView from "../page/StaffView.vue";
import {ElMessage} from "element-plus";

const routes =[
    {path:'/',redirect:'/index'},
    {path:'/login',name:'/login',component:() =>import('../page/StaffLogin.vue')},
    {path:'/index',component:()=>import('../components/MedicalHome.vue'),
        children:[
            {path:'/outPatient',name:'OutPatient',component:()=>import('../page/OutPatient.vue')},
            {path:'/pharmacy',name:'Pharmacy',component:()=>import('../page/Pharmacy.vue')},
            {path:'/billing',name:'BillingStation',component:()=>import('../page/BillingStation.vue')},
            {path:'/staffView',name: 'StaffView',component:() =>import('../page/StaffView.vue')},
            {path:'/wardView',name: 'WardView',component:() =>import('../page/WardView.vue')},
            {path:'/equipment',name: 'Equipment',component:() =>import('../page/Equipment.vue')},
            {path:'/examItem',name: 'ExamItem',component:() =>import('../page/ExamItem.vue')},
            {path:'/surgeryItem',name: 'SurgeryItem',component:() =>import('../page/SurgeryItem.vue')},
            {path:'/employees',name:'Employees',component:()=>import('../page/Employee.vue')},
            {path:'/wardNurse',name:'BedDashboardNursing',component:()=>import('../page/BedDashboardNursing.vue') },
            {path:'/inpatient-apply',name:'InpatientApplicationList',component:()=>import('../page/InpatientApplicationList.vue')},
            {path:'/discharge-apply',name:'DischargeApplicationList',component:()=>import('../page/DischargeApplicationList.vue')},
            {path:'/ward-doctor',name:'BedDashboard',component:()=>import('../page/BedDashboard.vue')},
            {path:'/bed',name: 'BedView',component:() =>import('../page/BedView.vue')},
            {path:'/permission',name: 'Permission',component:() =>import('../page/Permission.vue')},
            {path:'/patientSurgery',name: 'PatientSurgery',component:() =>import('../page/PatientSurgery.vue')},
            {path:'/patientExam',name: 'PatientExam',component:() =>import('../page/PatientExamView.vue')},
            {path:'/timeSlot',name: 'TimeSlotView',component:() =>import('../page/TimeSlotView.vue')}


        ]
    },
]

const router = createRouter({
    history:createWebHistory(),
    routes
})

router.beforeEach((to, from, next) => {
    let token = sessionStorage.getItem("token")
    if (to.path == '/login') {
        next()
    } else {
        if (token == null || token == '') {
            ElMessage.warning("请先登录")
            next({
                name: '/login'
            })
        } else {
            next()
        }
    }
})
export default router
